/** 
 *
 * Description: 
 *
 * @author lirong
 * @version 1.0
 * <pre>
 * Modification History: 
 * Date         Author      Version     Description 
 * ------------------------------------------------------------------ 
 * 2012-4-20    lirong       1.0        1.0 Version 
 * </pre>
 */

package com.creditease.mobile.util;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.creditease.mobile.rss.RssConst;

/**
 * 
 * Description:
 * 
 * @author lirong
 * @version 1.0
 * 
 *          <pre>
 * Modification History: 
 * Date         Author      Version     Description 
 * ------------------------------------------------------------------ 
 * 2012-4-20    lirong       1.0        1.0 Version
 * </pre>
 */

public class LogUtil {


	public static void d(String msg) {
		//log(msg, "d");
	}

	public static void i(String msg) {
		log(msg, "i");
	}

	public static void w(String msg) {
		log(msg, "w");
	}

	public static void e(String msg) {
		log(msg, "e");
	}

	protected static void log(String msg, String level) {

		File file = new File(RssConst.APPROOT+ "debug.txt");
		if (!file.getParentFile().exists()) {
			file.getParentFile().mkdirs();
		}
		OutputStream fos = null;
		try {
			fos = new FileOutputStream(file,true);
			BufferedOutputStream bos = new BufferedOutputStream(fos);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");

			StringBuilder builder = new StringBuilder();
			builder.append(sdf.format(new Date()));
			builder.append(" ");
			builder.append(level);
			builder.append(" ");
			builder.append(msg);
			bos.write(builder.toString().getBytes());
			bos.flush();
			bos.close();
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			if (fos != null) {
				try {
					fos.close();
				}
				catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}

}
